 let house_id = 0
 let house_index = 0
 Page({
   data: {
     dialogVisible: false,
     houseList: []
   },
   onLoad() {
     this.getHouseList()
   },
   async getHouseList() {
     const {
       code,
       data
     } = await wx.http.get('/room')
     // console.log(data);
     if (code !== 10000) return wx.utils.toast()
     this.setData({
       houseList: data
     })
   },
   // 点击侧滑组件中的删除按钮
   clickDeleteBtn(ev) {
     // console.log('点击了侧滑组件中的删除按钮')
     const {
       position,
       instance
     } = ev.detail

     if (position === 'right') {
       // 显示 Dialog 对话框
       this.setData({
         dialogVisible: true,
       })

       // 关闭 swiper-cell 滑块组件
       instance.close()
     }
   },
   // 确认框关闭
   async dialogClose(ev) {
     const {
       code
     } = await wx.http.delete(`/room/${house_id}`)
     //  console.log(res);
     //  console.log(ev);
     // console.log('确认框关闭了')
     //  console.log(ev.detail)
     if (code !== 10000) return wx.utils.toast()
     // 更新房屋列表数据
     this.data.houseList.splice(house_index, 1)
     this.setData({
       houseList: this.data.houseList
     })
   },

   goDetail(ev) {
     wx.navigateTo({
       url: `/house_pkg/pages/detail/index?id=` + ev.mark.id,
     })
   },

   addHouse() {
     wx.navigateTo({
       url: '/house_pkg/pages/locate/index',
     })
   },
   // 点击侧滑组件里面的删除按钮时会触发
   clickDeleteBtn(ev) {
     console.log(ev);
     console.log('点击了侧滑组件中的删除按钮')
     const {
       position,
       instance
     } = ev.detail
     if (position === 'right') {
       // 显示 Dialog 对话框
       this.setData({
         dialogVisible: true
       })
       house_id = ev.mark.id
       house_index = ev.mark.index
       // 关闭 swiper-cell 滑块组件
       instance.close()
     }
   },

 })